Blog search

Friday Facts #172 - Blending and Rendering

Posted by Posila & V453000 on 2017-01-06

Alpha blending and pre-multiplied alpha From time to time there is some confusion inside the team about how sprites are blended with the background when rendering, and what kind of effects we are able to achieve by tinting the sprites. So I (Posila) have decided to write up a few paragraphs about how alpha blending works (not only in Factorio), and what it means when someone talks about pre-multiplied alpha. When the GPU is figuring out what color it should draw on a particular pixel position, it runs a blending operation on just the computed pixel color and original color in the render target. There are several common blending operation modes (additive, multiplicative, overwrite, etc.), but the most common one used in Factorio is alpha blending. It calculates the resulting color using following equation (usually the new color is called 'source' and the background color that is being overwritten is called 'destination'): You can easily see that a source with alpha 0 will be fully transparent and the one with alpha 1 will be fully opaque. In games it is common to use a pre-multiplied alpha, which means the color channels of textures are stored in memory being already pre-multiplied by the alpha channel. Alpha blending with pre-multiplied alpha uses a simplified equation: Besides a slight performance gain from the GPU not having to do bunch of multiplication all the time, this equation allow us to do some extra effects we couldn't do without pre-multiplied alpha. Factorio renders sprites as colored polygons with texture. We usually refer to the color of a polygon as the 'tint', and every pixel of a sprite is multiplied with its tint. This is useful mainly for color masks, for example the diesel locomotive has a grayscale color mask which is tinted by the color it has set. Tints should have a pre-multiplied alpha too, but they don't have to, so we can use it to lie about the colors and alpha to the GPU. For example if we use tint {r=1,g=1,b=1,a=0} we can simplify previous equation even further and we get additive blending: This is great because that means we can switch between alpha and additive blending without having to change the blending state in graphics API, which would break sprite batching and result in an increase in the CPU cost of rendering. For some effects we use a tint with alpha between 0 and 1 heavily. This makes the result appear to be a combination of additive and alpha blending. For example, fire would eventually blend into a single solid color with pure additive blending, or would not look like it is emitting light with pure alpha blending. By using tint (1, 1, 1, 0.35) on the flame sprites, the brightness of overlapping flames adds up partially, but the flames don't completely lose their details. The same trick is used for smoke. Textures with pre-multiplied alpha also produce better results in texture filtering , which is probably the main reason why they are so widely used in the videogame industry.

Friday Facts #134 - Signal placement indicator

Posted by kovarex on 2016-04-15

Hello Factorio players!

Friday Facts #403 - Train stops 2.0

Posted by Klonan on 2024-03-22

Hello, When playing with trains, you tend to spend a lot of time building train stops. In my latest playtesting, I noticed a few annoyances and pain points, which we will go in to today, along with some other improvements for 2.0.

Friday Facts #299 - Everything is more complex than expected

Posted by kovarex on 2019-06-14

You might have noticed that a lot of rail related stuff was broken during these past releases, and now it is working more or less fine again. The story behind it is not so trivial.

Friday Facts #114 - Better train conditions

Posted by kovarex on 2015-11-27

Hello, it feels really nice these weeks. We actually have some time to improve the game instead of just fixing bugs. Lets take a look on some of the improvements.

Friday Facts #347 - New hope demo levels

Posted by Klonan, V453000 on 2020-05-15

New hope demo levels Klonan A few weeks ago we discussed the changes to the demo and tutorial in the game (FFF-342). One piece of feedback we received after publishing the news was about the old 'New hope' campaign levels, and specifically the 'Abandoned rail base/Broken rail map'. It seems a lot of you in the community really really enjoyed the new hope campaign levels, and several of the team here share the same feelings. After we scrapped the plans for a new campaign and reverted to the old demo, we had initially dismissed the idea to revive the New hope campaign... However due to popular demand... we have decided to bring back the favourites, the first 2 levels of the new hope campaign. This time though, they will also be included in the demo version of the game. This represents a very significant increase in scope for the demo, increasing the demo content to include research, red science, green science, trains, and much more. These levels should be ready for release within a week (but no promises).

Friday Facts #275 - 0.17 Science changes

Posted by V453000 & Albert on 2018-12-28

It's the last Friday of 2018, and as such the last Friday Facts before the New year of 2019. We all hope everyone has had a great 2018, and looking forward to a lot more automation fun to come in 2019. Albert has produced a postcard for you all to share to give the year a good send-off.

Friday Facts #140 - Soon

Posted by kovarex on 2016-05-27

Hello, the struggle to finish the latest features and fixes so 0.13 can be in time, or just reasonable delayed, goes on. There is always last missing icon or tweak that was hiding around the corner. It is still not certain whether we can really deliver next week, but we will certainly try to.

Friday Facts #178 - Minimal mode and Mini-tutorials

Posted by Klonan on 2017-02-17

Hello, the office has had a very lively atmosphere this week. With some very productive team discussions taking place, we reach another Friday with an optimistic outlook of the weeks to come.

Friday Facts #325 - New Explosions and Particles

Posted by Albert, Dom, Klonan on 2019-12-13

Hello, The year is wrapping up, and we have been hard at work finishing off some topics before we take our Christmas break. As you can imagine, releasing any new version of the game without a few weeks to do bugfixing wouldn't be wise, so you can rest easy this holiday period without the worry of a surprise 0.18 release.